/**
 * 
 */
package com.cea.papyrus.diagram.statemachine.command;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Region;

import com.cea.papyrus.core.commands.factories.DiagramElementDeleteCommandFactory;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * Delete factory specific to this diagram.
 * @author dumoulin
 *
 */
public class UMLDi2ElementDeleteFactory extends com.cea.papyrus.core.commands.factories.UMLDi2ElementDeleteFactory {

    /**
     * Singleton instance of the factory.
     */
    public static UMLDi2ElementDeleteFactory eINSTANCE = new UMLDi2ElementDeleteFactory();
    /**
     * Delete related graph elements.
     * 
     * @param command the command
     * @param elt the elt
     */
    protected void deleteRelatedGraphElements(Element elt, CompoundCommand command) {
        // Delete from diagrams
        Iterator graphElements = getModelManager().lookForGraphElement(elt, new ArrayList()).iterator();
        while(graphElements.hasNext()) {
            GraphElement ge = (GraphElement) graphElements.next();
            if(elt instanceof Region)
                command.add(new DeleteRegionNodeCommand((GraphNode)ge));
            else
                command.add(DiagramElementDeleteCommandFactory.eINSTANCE.createCommand(ge));
        }

    }

}
